// 全局注册
// Vue.component(组件名, 组件对象)
import PageTools from '@/components/PageTools'
import store from '@/store'
import MyCom from '@/components/MyCom'
import UploadImg from '@/components/UploadImg'
import ImageHolder from '@/components/ImageHolder'
import Lang from '@/components/Lang'
import ScreenFull from '@/components/ScreenFull'

// Vue.use()的作用：注册插件，增强Vue的功能
// 格式:
//   Vue.use(对象)，
//   对象中有一个install函数，Vue.use(对象)就调用install函数，并传入Vue
// Vue.use({install(Vue){
//
// }})

export default {
  install: function(Vue) {
    Vue.prototype.fn = () => { alert('fn') }

    // console.log('install...', a === Vue)
    Vue.component('PageTools', PageTools)
    Vue.component('MyCom', MyCom)
    Vue.component('Lang', Lang)
    Vue.component('UploadImg', UploadImg)
    Vue.component('ImageHolder', ImageHolder)
    Vue.component('ScreenFull', ScreenFull)
    Vue.directive('allow', {
      inserted(el, binding) {
        var point = store.state.user.userInfo.roles.points
        var flag = point.includes(binding.value)
        if (!flag) {
          el.parentNode.removeChild(el)
        }
      }
    })
    Vue.directive('img', {
      inserted(el, binding) {
        if (!binding.value) {
          el.src = 'https://cn.bing.com/images/search?view=detailV2&ccid=wc%2fdCG%2fK&id=2A67B025EDB55DFCC3EACFBF5B0CD513CC71AE39&thid=OIP.wc_dCG_KbIKZwMdtD3gL2QHaEt&mediaurl=https%3a%2f%2fpic3.zhimg.com%2fv2-58d652598269710fa67ec8d1c88d8f03_r.jpg%3fsource%3d1940ef5c&exph=1304&expw=2048&q=%e5%9b%be%e7%89%87&simid=607986392493932633&FORM=IRPRST&ck=7906E4DE8F66609504206A4E0B045F1E&selectedIndex=3&ajaxhist=0&ajaxserp=0'
        }
        el.onerror = () => {
          el.src = 'https://cn.bing.com/images/search?view=detailV2&ccid=wc%2fdCG%2fK&id=2A67B025EDB55DFCC3EACFBF5B0CD513CC71AE39&thid=OIP.wc_dCG_KbIKZwMdtD3gL2QHaEt&mediaurl=https%3a%2f%2fpic3.zhimg.com%2fv2-58d652598269710fa67ec8d1c88d8f03_r.jpg%3fsource%3d1940ef5c&exph=1304&expw=2048&q=%e5%9b%be%e7%89%87&simid=607986392493932633&FORM=IRPRST&ck=7906E4DE8F66609504206A4E0B045F1E&selectedIndex=3&ajaxhist=0&ajaxserp=0'
        }
      }
    })
  }

}

